package org.fireflow2.designer.eclipse.modelwrapper.basic;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Rectangle;
import org.fireflow.pdl.fpdl20.diagram.DiagramElement;
import org.fireflow.pdl.fpdl20.diagram.EndNodeShape;
import org.fireflow.pdl.fpdl20.diagram.Fpdl20DiagramElement;
import org.fireflow.pdl.fpdl20.diagram.basic.Circle;
import org.fireflow.pdl.fpdl20.process.EndNode;
import org.fireflow2.designer.eclipse.figures.EndNodeFigure;
import org.fireflow2.designer.eclipse.modelwrapper.NodeWrapper;
import org.fireflow2.designer.eclipse.modelwrapper.SubProcessWrapper;
import org.fireflow2.designer.eclipse.util.Util4Eclipse;

public class EndNodeWrapper extends NodeWrapper  {
	public EndNodeWrapper(SubProcessWrapper subflowWrapper,EndNode arg0,DiagramElement arg1){
		super(subflowWrapper,arg0,arg1);
	}
	public  String getElementType(){
		return Fpdl20DiagramElement.END_NODE.name();
	}	
	
	public Rectangle calculateBounds() {
		String displayName = this.getDisplayName();
		// 计算bounds
		EndNodeShape startShape = (EndNodeShape) this.getDiagramElement();
		Circle circle = (Circle) startShape.getShape();

		Dimension dimension = Util4Eclipse.getTextSize(circle.getLabel(),
				displayName);

		Rectangle rectangle = this.getBox();
		if (dimension.width > 0) {
			rectangle.height += EndNodeFigure.IconTextGap;
			rectangle.height += dimension.height;// 字体高度
			if (dimension.width > rectangle.width) {
				int oldWidth = rectangle.width;
				rectangle.width = dimension.width;
				rectangle.x -= ((dimension.width - oldWidth) / 2);
			}
		}
		return rectangle;
	}
}
